package cn.stylefeng.guns.modular.manager.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.manager.entity.FlowServiceAreaPrice;
import cn.stylefeng.guns.modular.manager.entity.FlowServiceDistancePrice;
import cn.stylefeng.guns.modular.manager.mapper.FlowServiceAreaPriceMapper;
import cn.stylefeng.guns.modular.manager.mapper.FlowServiceDistancePriceMapper;
import cn.stylefeng.guns.modular.manager.model.params.FlowServiceAreaPriceParam;
import cn.stylefeng.guns.modular.manager.model.params.FlowServiceDistancePriceParam;
import cn.stylefeng.guns.modular.manager.model.result.FlowServiceAreaPriceResult;
import cn.stylefeng.guns.modular.manager.service.FlowServiceAreaPriceService;
import cn.stylefeng.guns.modular.manager.service.FlowServiceDistancePriceService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
@Service
public class FlowServiceAreaPriceServiceImpl extends ServiceImpl<FlowServiceAreaPriceMapper, FlowServiceAreaPrice> implements FlowServiceAreaPriceService {
    @Override
    public void add(FlowServiceAreaPriceParam param) {
        FlowServiceAreaPrice entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FlowServiceAreaPriceParam param) {
        this.removeById(getKey(param));
    }

    @Override
    public void update(FlowServiceAreaPriceParam param) {
        FlowServiceAreaPrice oldEntity = getOldEntity(param);
        FlowServiceAreaPrice newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FlowServiceAreaPriceResult findBySpec(FlowServiceAreaPriceParam param) {
        return null;
    }

    @Override
    public List<FlowServiceAreaPriceResult> findListBySpec(FlowServiceAreaPriceParam param) {
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(FlowServiceAreaPriceParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(FlowServiceAreaPriceParam param){
        return param.getAreaPriceId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private FlowServiceAreaPrice getOldEntity(FlowServiceAreaPriceParam param) {
        return this.getById(getKey(param));
    }

    private FlowServiceAreaPrice getEntity(FlowServiceAreaPriceParam param) {
        FlowServiceAreaPrice entity = new FlowServiceAreaPrice();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }
}
